home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Resources / Developers / XAMPP 1.5.4 / Windows installer / xampp-win32-1.5.4-installer.exe / xampp / security / htdocs / securefunctions.php < prev    next >
PHP Script  |  2006-04-07  |  5KB  |  174 lines

  1. <?php
  2.     function mysqlrootupdate($currentpass, $newpass, $renewpass) {
  3.         $curdir = getcwd();
  4.         list($partwampp, $directorwampp) = spliti('\\\security\\\htdocs', $curdir);
  5.         $mypasswdtxt = "mysqlrootpasswd.txt";
  6.         $mypasswdtxtdir = $partwampp."\security\\".$mypasswdtxt;
  7.         $dir = $partwampp."\security\\";
  8.         global $rootpasswdupdate;
  9.         global $update;
  10.         global $mysqlpfile;
  11.         if (@mysql_connect("localhost", "root", "$currentpass")) {
  12.             mysql_select_db("mysql");
  13.  
  14.             mysql_query("SET PASSWORD = PASSWORD('$newpass')");  //Fix by Wiedmann
  15.             mysql_query("FLUSH PRIVILEGES");
  16.             mysql_close();
  17.  
  18.             if (!file_exists($dir)) { // Fix by Wiedmann
  19.                 mkdir($dir);
  20.             }
  21.             if ($mysqlpfile=="yes")
  22.             {
  23.             $datei = fopen($mypasswdtxtdir, 'w+');
  24.             $put = "mysql user = root\r\nmysql password = $newpass";
  25.             fputs($datei, $put);
  26.             fclose($datei);
  27.             }
  28.             $rootpasswdupdate = "yes";
  29.         } else {
  30.             $rootpasswdupdate = "no";
  31.         }
  32.     }
  33.  
  34.     function phpmyadminstatus() {
  35.         global $currentstatus;
  36.         global $authzeile;
  37.         global $notfind;
  38.  
  39.         $curdir = getcwd();
  40.         list($partwampp, $directorwampp) = spliti('\\\htdocs', $curdir);
  41.         $configinc = "config.inc.php";
  42.         $phpmyadminconf = $partwampp."\phpmyadmin\\".$configinc;
  43.  
  44.         if (file_exists($phpmyadminconf)) {
  45.             $datei = fopen($phpmyadminconf, 'r');
  46.             $i = 0;
  47.             while (!feof($datei)) {
  48.                 $zeile = fgets($datei, 255);
  49.                 $oldzeile[] = $zeile;
  50.                 @list($left, $right) = split('=', $zeile);
  51.                 if (preg_match("/'auth_type'/i", $left)) {
  52.                     if (preg_match("/'http'/i", $right)) {
  53.                         $currentstatus[] = "http";
  54.                         $authzeile[] = $i;
  55.                     } elseif (preg_match("/'cookie'/i", $right)) {
  56.                         $currentstatus[] = "cookie";
  57.                         $authzeile[] = $i;
  58.                     } else {
  59.                         $currentstatus[] = "null";
  60.                         $authzeile[] = $i;
  61.                     }
  62.                 }
  63.                 $i++;
  64.             }
  65.             fclose($datei);
  66.         } else {
  67.             $notfind = 1;
  68.         }
  69.     }
  70.  
  71.     function changephpadminauth($phpmyadminauth, $myupdate) {
  72.         global $phpmyadminconfsafe;
  73.         $curdir = getcwd();
  74.         list($partwampp, $directorwampp) = spliti('\\\security\\\htdocs', $curdir);
  75.         $configinc = "config.inc.php";
  76.         $phpmyadminconf = $partwampp."\phpmyadmin\\".$configinc;
  77.  
  78.         if (file_exists($phpmyadminconf)) {
  79.             $datei = fopen($phpmyadminconf, 'r');
  80.             $i = 0;
  81.             while (!feof($datei)) {
  82.                 $zeile = fgets($datei, 255);
  83.                 $oldzeile[] = $zeile;
  84.                 @list($left, $right) = split('=', $zeile);
  85.                 if (preg_match("/'auth_type'/i", $left)) {
  86.                     if (preg_match("/'http'/i", $right)) {
  87.                         $currentstatus[] = "http";
  88.                         $authzeile[] = $i;
  89.                     } elseif (preg_match("/'cookie'/i", $right)) {
  90.                         $currentstatus[] = "cookie";
  91.                         $authzeile[] = $i;
  92.                     } else {
  93.                         $currentstatus[] = "null";
  94.                         $authzeile[] = $i;
  95.                     }
  96.                 }
  97.                 $i++;
  98.             }
  99.             fclose($datei);
  100.         } else {
  101.             $notfind = 1;
  102.         }
  103.  
  104.         $mynewzeile = "\$cfg['Servers'][\$i]['auth_type']     = '$phpmyadminauth';      // Authentication method (config, http or cookie based)\n";
  105.  
  106.         if (file_exists($phpmyadminconf)) {
  107.             if (($currentstatus[0] == "null") || ($myupdate == "1")) {
  108.                 copy($phpmyadminconf, $phpmyadminconf.'.safe');
  109.                 $phpmyadminconfsafe = $partwampp."\phpmyadmin\\".$configinc.".safe";
  110.                 $phpmyadminauth = "http";
  111.                 $datei = fopen($phpmyadminconf, 'w+');
  112.                 if ($datei) {
  113.                     for ($z = 0; $z < $i + 1; $z++) {
  114.                         if ($authzeile[0] == $z) {
  115.                             fputs($datei, $mynewzeile);
  116.                         } else {
  117.                             fputs($datei, $oldzeile[$z]);
  118.                         }
  119.                     }
  120.                 }
  121.             }
  122.         }
  123.     }
  124.  
  125.     function htaccess($xauser, $xapasswd) {
  126.         global $xamppdirconfig;
  127.         global $xapasswdtxtdir;
  128.         global $htpasswddir;
  129.         global $htpasswddirectory;
  130.         global $htxampp;
  131.         global $xapfile;
  132.         $curdir = getcwd();
  133.         list($partwampp, $directorwampp) = spliti('\\\security\\\htdocs', $curdir);
  134.         $htaccess = ".htaccess";
  135.         $xapasswdtxt = "xamppdirpasswd.txt";
  136.         $htpasswd = "xampp.users";
  137.         $xapasswdtxtdir = $partwampp."\security\\".$xapasswdtxt;
  138.         $curspcript = $_SERVER["SCRIPT_FILENAME"];
  139.         $htxampp = $partwampp."\htdocs\\xampp\\".$htaccess;
  140.         $htpasswdexe = $partwampp."\apache\\bin\\htpasswd.exe";
  141.         if (file_exists($htpasswdexe)) {
  142.             $htpasswddir = "\"".$partwampp."\security\\".$htpasswd."\"";
  143.             $htpasswddirectory = $partwampp."\security\\".$htpasswd;
  144.             $dir = $partwampp."\security\\";
  145.             if (!file_exists($dir)) {
  146.                 mkdir($dir);
  147.             }
  148.  
  149.             $datei = fopen($htxampp, 'w+');
  150.             $insert = "AuthName \"xampp user\"\r\nAuthType Basic\r\nAuthUserFile $htpasswddir\r\nrequire valid-user";
  151.             fputs($datei,$insert);
  152.             fclose($datei);
  153.  
  154.             chdir($partwampp."\security"); // Fix by Wiedmann
  155.             $htpassrealm = "start /b \"\" \"$htpasswdexe\" -c -m -b .\\xampp.users $xauser $xapasswd";
  156.             $handle = popen($htpassrealm, 'w');
  157.             pclose($handle);
  158.             chdir($curdir);
  159.             if ($xapfile=="yes")
  160.             {
  161.             $datei = fopen($xapasswdtxtdir, 'w+');
  162.             $put = "XAMPP user = $xauser\r\nXAMPP password = $xapasswd";
  163.             fputs($datei, $put);
  164.             fclose($datei);
  165.             }
  166.             $hdir = $dir.'htdocs\\';
  167.             copy($htxampp, $dir.'htdocs\\.htaccess');
  168.             $xamppdirconfig = "ok";
  169.         } else {
  170.             $xamppdirconfig = "notok";
  171.         }
  172.     }
  173. ?>
  174.